package edu.arizona.eller.mis.hippo.bo;

import java.util.ArrayList;
import java.util.List;

import edu.arizona.eller.mis.hippo.adapter.ProductSearch;
import edu.arizona.eller.mis.hippo.bean.Product;
import edu.arizona.eller.mis.hippo.exception.SimpleException;
import edu.arizona.eller.mis.hippo.factory.ProductSearchFactory;


public class SearchProductsBO {
	public void executeUserSearchAndPrint(String searchTerm, String searchCondition, ProductSearch ps){	
		try {
			List<Product> pList = runFullSearch(ps, searchTerm, searchCondition);
			System.out.println("Results for " + ps.getClass().getSimpleName() + " - ");
			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
			for (Product product : pList) {
				System.out.println(product.toString());
				System.out.println("**************************************************");
			}
		} catch (SimpleException e) {
			e.printStackTrace();
		}
	}
	
	private List<Product> runFullSearch(ProductSearch ps, String searchTerm, String searchCondition) throws SimpleException{
		List<Product> pList = new ArrayList<Product>();
		
		pList = ps.keywordSearch(searchTerm);
		
		return pList;
		
	}
	
	public static void main(String[] args){
		SearchProductsBO s = new SearchProductsBO();
		ProductSearchFactory pf = ProductSearchFactory.getInstance();
		s.executeUserSearchAndPrint("hat", null, pf.getProductSearch("craigslist"));
	}
}
